<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">

    <input type="hidden" id="batchNo">

    <div class="layuimini-main">
        <table class="layui-hide" id="importTerminalTable" lay-filter="currentTableFilter"></table>
    </div>
</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        const host = `${window.location.protocol}//${window.location.host}`;

        $.ajaxSetup({
            headers: {'Access-Token': sessionStorage.getItem('token'), 'userId': sessionStorage.getItem("userId")}
        });

        $('#batchNo').click(function () {
            loadTable($('#batchNo').val())
        });


        function loadTable(batchNo) {
            $.get(`${host}/import/data/list`, {'batchNo': `${batchNo}`}, rest => {
                if (rest.code === '00') {
                    table.render({
                        elem: '#importTerminalTable',
                        method: 'get',
                        data: rest.data,
                        toolbar: '#toolbar',
                        // defaultToolbar: ['filter', 'exports', 'print'],
                        cols: [[
                            // {type: "checkbox", width: 50},
                            // {field: 'id', width: 80, title: 'ID'},
                            {field: 'organizationCode', width: 180, title: '机构号'},
                            {field: 'appName', width: 180, title: '应用名称'},
                            {field: 'funcName', width: 180, title: '功能名称'},
                            {field: 'sn', width: 180, title: '序列号(SN)'},
                            {field: 'terminalType', width: 180, title: '型号'},
                            {field: 'expiryType', width: 180, title: '激活有效期'},
                            {field: 'never', width: 180, title: '长期有效标识'},
                            {field: 'activeStatus', width: 180, title: '终端状态'},
                            {field: 'custName', width: 180, title: '商户名称'},
                            {field: 'custMobile', width: 180, title: '电话号码'},
                            {field: 'position', width: 180, title: '安装地址'},
                            {field: 'area', width: 180, title: '安装区县'},
                            {field: 'area', width: 180, title: '导入状态', fixed: 'right', templet: d => {
                                if (0 === d.dataStatus) {
                                    return '未导入'
                                }
                                if (1 === d.dataStatus) {
                                    return `<span style="color:#008000">成功<span>`;
                                }
                                if (2 === d.dataStatus) {
                                    return `<span style="color:#ff0000">失败(${d.msg})<span>`;
                                }
                            }}
                            // {title: '操作', fixed: 'right', minWidth: 150, toolbar: '#importTerminalTableBar', align: "center"}
                        ]],
                        limits: [10, 15, 20, 25, 50, 100],
                        limit: 15,
                        page: false,
                        skin: 'line',
                    });
                }
            });
        }


        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('currentTableId', {
                page: { current: 1 },
                where: { 'searchParams' : result }
            }, 'data');
            return false;
        });

    });
</script>

</body>
</html>